package com.gz.mylife.app;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gz.mylife.Define;
import com.gz.mylife.R;
import com.gz.mylife.adapter.AdvertFragment;
import com.gz.mylife.adapter.AdvertFragmentAdapter;
import com.gz.mylife.adapter.BaseAdapterHelper;
import com.gz.mylife.adapter.QuickAdapter;
import com.gz.mylife.im.ChatSession;
import com.gz.mylife.util.ToastUtils;
import com.gz.mylife.widget.LoadingCover;
import com.gz.mylife.widget.OfflineDialog;
import com.gz.mylife.widget.PageIndicator;
import com.gz.mylife.widget.LoadingCover.OnLoadingCoverRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.zl.smartmall.library.IGZAddress;
import com.zl.smartmall.library.IShoppingCart;
import com.zl.smartmall.library.ISmartMall;
import com.zl.smartmall.library.listener.AddToShoppingCartListener;
import com.zl.smartmall.library.listener.ProductDetailListener;
import com.zl.smartmall.library.po.PictureInfo;
import com.zl.smartmall.library.po.ProductDetailGraphicDetailInfo;
import com.zl.smartmall.library.po.ProductDetailInfo;
import com.zl.smartmall.library.po.ProductEvaluationInfo;
import com.zl.smartmall.library.util.CrashHandler;
import com.zl.smartmall.library.util.Tools;

public class ProductDetail extends BaseActivity implements OnClickListener,
		OnLoadingCoverRefreshListener {

	private static final int MIN_BUY_COUNT = 1;

	private static final String TAG = ProductDetail.class.getSimpleName();

	private int mProductId;
	private int mShopId;
	private int mBrandId;
	private int mMinBuyCount = MIN_BUY_COUNT;

	private AdvertFragmentAdapter mAdvertFragmentAdapter;
	private DisplayImageOptions mPictureOption;
	private LayoutInflater mInflater;
	private ProductDetailInfo mProductDetailModel;
	private QuickAdapter<ProductDetailGraphicDetailInfo> mAdapter;

	private LoadingCover mLoadingCover;
	private PageIndicator mPageIndicator;
	private PullToRefreshListView mPullList;
	private TextView mProductIntro;
	private TextView mCurrentCost;
	private TextView mOriginalCost;
	private TextView mMarketCost;
	private TextView mSaleNum;
	private TextView mBuyCount;
	private Button mAddToShoppingCart;
	private ViewPager mViewPager;
	private View mHeadView;
	private LinearLayout mLayoutLabel;
	// private LinearLayout mLoadingData;
	private Dialog mProgressDialog;
	private TextView cartGoodsCount;
	private ImageView[] picture;
	private ImageView mCommentPortrait;
	private TextView mCommentNickname;
	private TextView mCommentDate;
	private TextView mCommentContent;
	private TextView mCommentTitle;
	private TextView mCommentCount;
	private TextView mGoldCount;
	private TextView mTvCustomerService;
	private TextView mTvDiscount;
	private TextView mTvShopTime;
	private TextView mTvShopName;
	private View mCommentLayout;
	// private View mCustomerServiceLayout;
	private OfflineDialog mOfflineDialog;
	private Button iv_menu_shopping_cart;// 购物车
	private int nottimes;// 服务器的时间
	private int days; // 天
	private int hours; // 时
	private int minutes; // 分
	private int seconds; // 秒
	private int times = 0;
	private TextView tv_day;
	private TextView tv_hour;
	private TextView tv_minutes;
	private TextView tv_seconds;
	private RelativeLayout layout_timer;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_product_detail);

		mProductId = getIntent().getIntExtra("productId", 0);
		mShopId = getIntent().getIntExtra("shopId", 0);
		mBrandId = getIntent().getIntExtra("mBrandId", 0);
		// mActionBar.setTitle("商品详情");
		setActionbarTitle("商品详情", false);
		mAdvertFragmentAdapter = new AdvertFragmentAdapter(
				getSupportFragmentManager());
		mPictureOption = buildPictureOptions();
		mAdapter = buildAdater();
		mInflater = getLayoutInflater();

		findViewById(R.id.iv_decrease).setOnClickListener(this);
		findViewById(R.id.iv_increase).setOnClickListener(this);
		findViewById(R.id.btn_buy).setOnClickListener(this);
		mProgressDialog = new Dialog(this, R.style.DialogTheme);
		View view = View.inflate(this, R.layout.loading_popup, null);
		mProgressDialog.setContentView(view);
		mProgressDialog.setCanceledOnTouchOutside(false);
		mBuyCount = (TextView) findViewById(R.id.tv_buy_count);
		mBuyCount.setText("" + mMinBuyCount);
		mLoadingCover = (LoadingCover) findViewById(R.id.layout_loading_cover);
		mLoadingCover.setOnLoadingCoverRefreshListener(this);
		mHeadView = getLayoutInflater().inflate(R.layout.product_detail_head,
				null);
		mTvDiscount = (TextView) mHeadView.findViewById(R.id.tv_discount);
		mLayoutLabel = (LinearLayout) mHeadView.findViewById(R.id.layout_label);
		mViewPager = (ViewPager) mHeadView.findViewById(R.id.pager);
		mViewPager.setAdapter(mAdvertFragmentAdapter);
		mPageIndicator = (PageIndicator) mHeadView
				.findViewById(R.id.page_indicator);
		mPageIndicator.setViewPage(mViewPager);
		mProductIntro = (TextView) mHeadView
				.findViewById(R.id.tv_product_intro);
		mCurrentCost = (TextView) mHeadView.findViewById(R.id.tv_current_cost);
		mOriginalCost = (TextView) mHeadView
				.findViewById(R.id.tv_original_cost);
		mMarketCost = (TextView) mHeadView.findViewById(R.id.tv_market_cost);
		mSaleNum = (TextView) mHeadView.findViewById(R.id.tv_sale_num);
		mCommentCount = (TextView) mHeadView
				.findViewById(R.id.tv_comments_count);
		mGoldCount = (TextView) mHeadView
				.findViewById(R.id.tv_product_use_gold);
		// mCustomerServiceLayout =
		// mHeadView.findViewById(R.id.layout_customer_service);
		// mCustomerServiceLayout.setOnClickListener(this);
		mAddToShoppingCart = (Button) findViewById(R.id.tv_add_to_shopping_cart);
		mAddToShoppingCart.setOnClickListener(this);
		mTvCustomerService = (TextView) mHeadView
				.findViewById(R.id.tv_customer_service);
		mTvCustomerService.setOnClickListener(this);
		mTvShopTime = (TextView) mHeadView.findViewById(R.id.shop_time);
		mTvShopName = (TextView) mHeadView.findViewById(R.id.tv_shop_name);
		iv_menu_shopping_cart = (Button) findViewById(R.id.iv_menu_shopping_cart);// 左下方购物车按钮
		iv_menu_shopping_cart.setOnClickListener(this);
		View commentFooterView = mInflater.inflate(
				R.layout.product_detail_comment_footer, null);
		commentFooterView.setOnClickListener(this);
		View deliveryFooterView = mInflater.inflate(
				R.layout.product_detail_delivery_footer, null);
		deliveryFooterView.setOnClickListener(this);
		mCommentContent = (TextView) commentFooterView
				.findViewById(R.id.tv_content);
		mCommentDate = (TextView) commentFooterView.findViewById(R.id.tv_date);
		mCommentNickname = (TextView) commentFooterView
				.findViewById(R.id.tv_nickname);
		mCommentPortrait = (ImageView) commentFooterView
				.findViewById(R.id.iv_portrait);
		mCommentTitle = (TextView) commentFooterView
				.findViewById(R.id.tv_comment_title);
		mCommentLayout = commentFooterView.findViewById(R.id.layout_comment);
		picture = new ImageView[] {
				(ImageView) commentFooterView.findViewById(R.id.iv_picture1),
				(ImageView) commentFooterView.findViewById(R.id.iv_picture2),
				(ImageView) commentFooterView.findViewById(R.id.iv_picture3),
				(ImageView) commentFooterView.findViewById(R.id.iv_picture4) };

		mPullList = (PullToRefreshListView) findViewById(R.id.list);
		mPullList.getRefreshableView().addHeaderView(mHeadView);
		mPullList.getRefreshableView().addFooterView(deliveryFooterView);
		mPullList.getRefreshableView().addFooterView(commentFooterView);
		mPullList.setAdapter(mAdapter);
		mPullList.setMode(Mode.DISABLED);

		mOfflineDialog = (OfflineDialog) mInflater.inflate(
				R.layout.offline_dialog, null);
		tv_day = (TextView) mHeadView.findViewById(R.id.tv_day);
		tv_hour = (TextView) mHeadView.findViewById(R.id.tv_hour);
		tv_minutes = (TextView) mHeadView.findViewById(R.id.tv_minute);
		tv_seconds = (TextView) mHeadView.findViewById(R.id.tv_second);
		layout_timer = (RelativeLayout) mHeadView
				.findViewById(R.id.layout_timer);

		loadDataFromServer();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		// getMenuInflater().inflate(R.menu.product_detail, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent;
		switch (v.getId()) {
		case R.id.iv_decrease:
			if (mMinBuyCount > MIN_BUY_COUNT) {
				mBuyCount.setText("" + --mMinBuyCount);
			}
			break;

		case R.id.iv_increase:
			mBuyCount.setText("" + ++mMinBuyCount);
			break;

		case R.id.btn_buy:
			if (IGZAddress.getInstance().hasCommunity()) {
				buyImmediately();
			} else {
				ToastUtils.showToast(getApplicationContext(), "亲, 您还没绑定小区");
			}
			break;
		case R.id.tv_add_to_shopping_cart:
			if (IGZAddress.getInstance().hasCommunity()) {
				addToShoppingCart();
			} else {
				ToastUtils.showToast(getApplicationContext(), "亲, 您还没绑定小区");
			}
			break;

		case R.id.layout_comment_root:
			if (mProductDetailModel.getEvaluations() != null
					&& mProductDetailModel.getEvaluations().size() > 0) {
				intent = new Intent(getApplicationContext(),
						ProductCommentDetail.class);
				intent.putExtra("productId", mProductId);
				startActivity(intent);
			}
			break;

		case R.id.tv_customer_service:
			if (mProductDetailModel.getCustomerServices().size() > 0) {
				intent = new Intent();
				// intent.setClass(getApplicationContext(),
				// PrivateLetter.class);
				intent.setClass(getApplicationContext(), ChatSession.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				intent.putExtra("fuid", mProductDetailModel
						.getCustomerServices().get(0).getUid());
				intent.putExtra("nickname", mProductDetailModel
						.getCustomerServices().get(0).getNickname());
				intent.putExtra("gender", mProductDetailModel
						.getCustomerServices().get(0).getGender());
				intent.putExtra("face", mProductDetailModel
						.getCustomerServices().get(0).getFace());
				startActivity(intent);
			}
			break;

		case R.id.delivery_footer:
			intent = new Intent(getApplicationContext(), DeliveryExplain.class);
			intent.putExtra("url", mProductDetailModel.getDeliveryUrl());
			startActivity(intent);
			CrashHandler.d(TAG,
					"配送url = " + mProductDetailModel.getDeliveryUrl());
			break;
		case R.id.iv_menu_shopping_cart:// 点击购物车图标进入购物车页面
			intent = new Intent(getApplicationContext(), Plaza.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
			intent.putExtra("page_index", 3);
			startActivity(intent);
			finish();
			break;
		}
	}

	@Override
	public void onLoadingCoverRefresh() {
		// TODO Auto-generated method stub

	}

	private void addToShoppingCart() {
		// TODO Auto-generated method stub
		IShoppingCart.getInstance().addToShoppingCart(mBrandId, mShopId,
				mProductId, mMinBuyCount, new AddToShoppingCartListener() {

					@Override
					public void onResponseFailed() {
						// TODO Auto-generated method stub
						ToastUtils.showToast(getApplicationContext(),
								Define.MSG_OPERATE_FAILED_RETRY);
					}

					@Override
					public void onOffline() {
						// TODO Auto-generated method stub
						mOfflineDialog.show();
					}

					@Override
					public void onNoNetWork() {
						// TODO Auto-generated method stub
						ToastUtils.showToast(getApplicationContext(),
								Define.MSG_NO_NETWORK);
					}

					@Override
					public void onNoMoreData() {
						// TODO Auto-generated method stub

					}

					@Override
					public void onResponseSuccess(int activitiesId, int shopId,
							int productId, int buyNum, int cartNum) {
						// TODO Auto-generated method stub
						// 通过广播刷新购物车
						Intent broastIntent = new Intent(
								Define.ACTION_REFRESH_SHOPPING_CART);
						broastIntent.putExtra("shopId", mShopId);
						broastIntent.putExtra("productId", mProductId);
						sendBroadcast(broastIntent);
						ToastUtils
								.showToast(getApplicationContext(), "添加购物车成功");
					}
				});
	}

	private void buyImmediately() {
		// TODO Auto-generated method stub
		IShoppingCart.getInstance().addToShoppingCart(mBrandId, mShopId,
				mProductId, mMinBuyCount, new AddToShoppingCartListener() {

					@Override
					public void onResponseFailed() {
						// TODO Auto-generated method stub
						ToastUtils.showToast(getApplicationContext(),
								Define.MSG_OPERATE_FAILED_RETRY);
					}

					@Override
					public void onOffline() {
						// TODO Auto-generated method stub
						mOfflineDialog.show();
					}

					@Override
					public void onNoNetWork() {
						// TODO Auto-generated method stub
						ToastUtils.showToast(getApplicationContext(),
								Define.MSG_NO_NETWORK);
					}

					@Override
					public void onNoMoreData() {
						// TODO Auto-generated method stub

					}

					@Override
					public void onResponseSuccess(int activitiesId, int shopId,
							int productId, int buyNum, int cartNum) {
						// TODO Auto-generated method stub
						// 通过广播刷新购物车
						Intent broastIntent = new Intent(
								Define.ACTION_REFRESH_SHOPPING_CART);
						broastIntent.putExtra("shopId", mShopId);
						broastIntent.putExtra("productId", mProductId);
						broastIntent.putExtra("immediate", true);
						sendBroadcast(broastIntent);

						Intent intent = new Intent(getApplicationContext(),
								Plaza.class);
						intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
						intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
						intent.putExtra("page_index", 3);
						startActivity(intent);
						finish();
					}
				});
	}

	private QuickAdapter<ProductDetailGraphicDetailInfo> buildAdater() {
		return new QuickAdapter<ProductDetailGraphicDetailInfo>(
				getApplicationContext(), R.layout.product_detail_graphic,
				new ArrayList<ProductDetailGraphicDetailInfo>()) {

			@Override
			protected void convert(BaseAdapterHelper helper,
					ProductDetailGraphicDetailInfo item) {
				if (TextUtils.isEmpty(item.getUrl())) {
					helper.getView(R.id.iv_graphic).setVisibility(View.GONE);
				} else {
					// int[] size = Tools.fixSize(item.getWidth(),
					// item.getHeight(), mAbsoluteWidth);
					// LayoutParams params =
					// helper.retrieveView(R.id.iv_graphic).getLayoutParams();
					// params.width = size[0];
					// params.height = size[1];
					helper.setImageUrl(R.id.iv_graphic, item.getUrl(),
							mPictureOption);
					helper.getView(R.id.iv_graphic).setVisibility(View.VISIBLE);
				}
				if (TextUtils.isEmpty(item.getTitle())) {
					helper.getView(R.id.tv_title).setVisibility(View.GONE);
				} else {
					helper.setText(R.id.tv_title, item.getTitle());
					helper.getView(R.id.tv_title).setVisibility(View.VISIBLE);
				}
				if (TextUtils.isEmpty(item.getIntro())) {
					helper.getView(R.id.tv_intro).setVisibility(View.GONE);
				} else {
					helper.setText(R.id.tv_intro, item.getIntro());
					helper.getView(R.id.tv_intro).setVisibility(View.VISIBLE);
				}
			}
		};
	}

	private ProductDetailListener builderListener() {
		return new ProductDetailListener() {

			@Override
			public void onResponseFailed() {
				// TODO Auto-generated method stub
				mLoadingCover.onRefreshFailed();
			}

			@Override
			public void onOffline() {
				// TODO Auto-generated method stub
				mOfflineDialog.show();
				mLoadingCover.onRefreshFailed(Define.MSG_OFFLINE_ERROR);
			}

			@Override
			public void onNoNetWork() {
				// TODO Auto-generated method stub
				mLoadingCover.onRefreshFailed(Define.MSG_NO_NETWORK);
			}

			@Override
			public void onNoMoreData() {
				// TODO Auto-generated method stub
				mLoadingCover.onRefreshFailed(Define.MSG_NOTHING);
			}

			@Override
			public void onResponseSuccess(ProductDetailInfo productDetailInfo,
					int nowtime) {
				// TODO Auto-generated method stub
				mProductDetailModel = productDetailInfo;
				nottimes = nowtime;
				refreshAdvert(productDetailInfo.getProductPictures());
				refreshHeadView();
				// refreshSpecifications();
				mAdapter.clear();
				mAdapter.addAll(productDetailInfo.getGraphicDetails());
				mLoadingCover.onRefreshSuccess();
			}
		};
	}

	private DisplayImageOptions buildPictureOptions() {
		return new DisplayImageOptions.Builder().resetViewBeforeLoading(true)
				.bitmapConfig(Bitmap.Config.ARGB_8888).cacheInMemory(true)
				.cacheOnDisk(true).showImageOnLoading(R.color.transparent)
				.showImageOnFail(R.color.transparent)
				.showImageForEmptyUri(R.color.transparent)
				.imageScaleType(ImageScaleType.EXACTLY).build();
	}

	private void loadDataFromServer() {
		ISmartMall.getInstance().getProductDetail(mShopId, mProductId,
				builderListener());
	}

	private void refreshAdvert(List<PictureInfo> advertInfos) {
		CrashHandler.d(TAG, "advert size = " + advertInfos.size());
		List<AdvertFragment> fragments = new ArrayList<AdvertFragment>();
		for (int i = 0; i < advertInfos.size(); i++) {
			AdvertFragment fragment = AdvertFragment.newInstance(null,
					advertInfos.get(i).getUrl());
			fragments.add(fragment);
		}
		if (advertInfos.size() > 1) {
			mPageIndicator.setVisibility(View.VISIBLE);
		} else {
			mPageIndicator.setVisibility(View.GONE);
		}

		mAdvertFragmentAdapter.clear();
		mAdvertFragmentAdapter.addAll(fragments);
		mAdvertFragmentAdapter.notifyDataSetChanged();
		mPageIndicator.notifyDataSetChanged();
	}

	private void refreshHeadView() {
		times = mProductDetailModel.getMsendtime() - nottimes;
		if (mProductDetailModel.getMsendtime() == 0) {
			layout_timer.setVisibility(View.GONE);
		} else {
			layout_timer.setVisibility(View.VISIBLE);
			if (times <= 0) {
				findViewById(R.id.btn_buy).setBackgroundResource(
						R.drawable.btn_gray_normal);
				mAddToShoppingCart
						.setBackgroundResource(R.drawable.btn_gray_normal);
				findViewById(R.id.btn_buy).setEnabled(false);
				mAddToShoppingCart.setEnabled(false);
			} else {
				initTimer();
			}

		}
		mProductIntro.setText(mProductDetailModel.getProductIntros());
		mCurrentCost.setText("￥" + mProductDetailModel.getCurrentCost());
		mOriginalCost.setText("原价￥" + mProductDetailModel.getOriginalCost());
		mOriginalCost.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
		mMarketCost.setText("市场价：" + mProductDetailModel.getMarketCost());
		mMarketCost.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
		// mSaleNum.setText("销量  " + mProductDetailModel.getSaleNum());
		mSaleNum.setText(mProductDetailModel.getSaleNum() > 0 ? mProductDetailModel
				.getSaleNum() + "人认为值"
				: "");
		mCommentCount.setText("评价 " + mProductDetailModel.getCommentsCount());
		// mGoldCount.setText("金豆用户可用" + mProductDetailModel.getGold() +
		// Define.VOUCHER_NAME + ", 再抵"
		// + new
		// DecimalFormat("0.00").format(mProductDetailModel.getGoldToMoney()) +
		// "元");
		if (mProductDetailModel.getGold() > 0) {
			mGoldCount.setText("还可用" + mProductDetailModel.getGold()
					+ Define.VOUCHER_NAME + "折抵现金");
			mGoldCount.setVisibility(View.VISIBLE);
		} else {
			mGoldCount.setVisibility(View.GONE);
		}
		double discount = mProductDetailModel.getCurrentCost()
				/ mProductDetailModel.getOriginalCost();
		String discountStr = mProductDetailModel.getCurrentCost() == mProductDetailModel
				.getOriginalCost() ? "无折扣" : new DecimalFormat("0.0")
				.format(discount * 10) + "折";
		mTvDiscount.setText(discountStr);
		if (mProductDetailModel.getCurrentCost() == mProductDetailModel
				.getOriginalCost()) {
			mTvDiscount.setVisibility(View.INVISIBLE);
		}
		mTvShopTime.setText("营业时间：" + mProductDetailModel.getOpenTime());
		mTvShopName.setText(mProductDetailModel.getShopName());
		// if(mModel.getCustomerServices() != null &&
		// mModel.getCustomerServices().size() > 0) {
		// mCustomerServiceLayout.setVisibility(View.VISIBLE);
		// }else {
		// mCustomerServiceLayout.setVisibility(View.GONE);
		// }

		List<String> label = mProductDetailModel.getLabels();
		for (int i = 0; i < label.size(); i++) {
			// int background = "赠品".equals(label.get(i)) ?
			// R.drawable.bg_gift : R.drawable.bg_free_express;
			View view = mInflater.inflate(R.layout.product_label, mLayoutLabel,
					false);
			view.setBackgroundResource(R.drawable.bg_mall_promotion_label);
			((TextView) view).setText(label.get(i));
			mLayoutLabel.addView(view);
			view.setPadding(Tools.dip2px(getApplicationContext(), 3), 0,
					Tools.dip2px(getApplicationContext(), 3), 0);
			((LinearLayout.LayoutParams) view.getLayoutParams()).leftMargin = Tools
					.dip2px(getApplicationContext(), 4);
		}

		ProductEvaluationInfo item = mProductDetailModel.getEvaluations()
				.size() > 0 ? mProductDetailModel.getEvaluations().get(0)
				: null;
		if (item != null) {
			for (int i = 0; i < 4; i++) {
				if (i < item.getPictures().size()) {
					picture[i].setVisibility(View.VISIBLE);
					ImageLoader.getInstance().displayImage(
							item.getPictures().get(i).getUrl(), picture[i],
							mPictureOption);
				} else {
					picture[i].setVisibility(View.GONE);
				}
			}
			ImageLoader.getInstance().displayImage(item.getFace(),
					mCommentPortrait, mPictureOption);
			mCommentNickname.setText(item.getNickname());
			if (TextUtils.isEmpty(item.getCommentContent().trim())) {
				mCommentContent.setVisibility(View.GONE);
			} else {
				mCommentContent.setText(item.getCommentContent());
				mCommentContent.setVisibility(View.VISIBLE);
			}
			mCommentDate.setText(Tools.formatTimeStampString(
					getApplicationContext(), item.getCommentTime(), false));
		} else {
			mCommentTitle.setText("暂无评论");
			mCommentLayout.setVisibility(View.GONE);
			findViewById(R.id.tv_check_more_comments).setVisibility(View.GONE);
		}

	}

	/**
	 * 限时抢购倒计时
	 */
	private void initTimer() {
		tv_day.post(new Runnable() {

			@Override
			public void run() {
				if (times > 0) {

					times--;
					days = times / (24 * 60 * 60);
					hours = (times / (60 * 60)) - (days * 24);
					minutes = (times / 60) - days * 24 * 60 - hours * 60;
					seconds = times - days * 24 * 60 * 60 - hours * 60 * 60
							- minutes * 60;
					StringBuffer day = new StringBuffer();
					StringBuffer hour = new StringBuffer();
					StringBuffer minute = new StringBuffer();
					StringBuffer second = new StringBuffer();
					if (days < 10) {
						day.append(0);
					}
					if (hours < 10) {
						hour.append(0);
					}
					if (minutes < 10) {
						minute.append(0);
					}
					if (seconds < 10) {
						second.append(0);
					}
					day.append(days);
					hour.append(hours);
					minute.append(minutes);
					second.append(seconds);
					tv_day.setText(day);
					tv_hour.setText(hour);
					tv_minutes.setText(minute);
					tv_seconds.setText(second);
					tv_day.postDelayed(this, 1000);
					if (days == 0 && hours == 0 && minutes == 0 && seconds == 0) {// 当倒计时的时间到点时，设置假如购物车按钮和立即购买按钮为失效
						findViewById(R.id.btn_buy).setBackgroundResource(
								R.drawable.btn_gray_normal);
						mAddToShoppingCart
								.setBackgroundResource(R.drawable.btn_gray_normal);
						findViewById(R.id.btn_buy).setEnabled(false);
						mAddToShoppingCart.setEnabled(false);
					}
				}
			}

		});
	}

}
